home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / ResEdit / ResEdit 2.0b2 / Examples / PExamples / Source / ICON.Pick.p < prev    next >
Encoding:
Text File  |  1990-04-02  |  4.0 KB  |  158 lines  |  [TEXT/MPS ]

  1. {
  2.  COPYRIGHT (C) 1984-1990 Apple Computer,Inc.
  3.  All rights reserved
  4. }
  5.  
  6. UNIT IconPick;
  7.  
  8. { Icon Resource Picker }
  9.  
  10. { This is the Icon resource picker.  This picker is very similar to all other pickers.
  11.     The general scheme is that a List structure is created whose cells
  12.     contain the ID's of this resource type.  A drawproc is installed in the List
  13.     record which is called to display the resource.  Obviously, graphical resources
  14.     are drawn as is, but descriptions of other types can be displayed also (usually
  15.     in a one-dimensional list). }
  16.  
  17. INTERFACE
  18.  
  19. USES    MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf,
  20.             ResEd;
  21.  
  22. PROCEDURE EditBirth(thing: Handle; dad: ParentHandle);
  23. PROCEDURE PickBirth(t: ResType; dad: ParentHandle);
  24. PROCEDURE DoEvent(VAR evt: EventRecord; pick: PickHandle);
  25. PROCEDURE DoInfoUpdate(oldID, newID: INTEGER; pick: PickHandle);
  26. FUNCTION IsThisYours (thing: Handle; pick: PickHandle): BOOLEAN;
  27. PROCEDURE DoMenu(menu, item: INTEGER; pick: PickHandle);
  28.  
  29. IMPLEMENTATION
  30.  
  31. CONST
  32.     listCellSizeH = $38;
  33.     listCellSizeV = $42;
  34.     
  35.     { Needs to be 2 wide so that I can always tell a 2d list from a normal text list. }
  36.     minIconsPerRow = 2;
  37.     ICONMinWindowWidth = (minIconsPerRow * listCellSizeH) + theScrollBar;
  38.     ICONMinWindowHeight = listCellSizeV;
  39.     
  40.     ICONResourceSize = 128;
  41.  
  42. {$R-}
  43.  
  44. PROCEDURE EditBirth(thing: Handle; dad: ParentHandle);
  45.  
  46.     BEGIN
  47.     END;
  48.  
  49. { *********************************************************************************** }
  50.  
  51. { Returns the width and the iconsPerRow. }
  52. FUNCTION GetWidth (VAR iconsPerRow: INTEGER): INTEGER;
  53.  
  54. VAR
  55.     width: INTEGER;
  56.  
  57. BEGIN
  58. width := PickStdWidth;
  59. IF width > ICONMinWindowWidth THEN
  60.     BEGIN
  61.     iconsPerRow := (width - theScrollBar) DIV listCellSizeH;
  62.     width := (iconsPerRow * listCellSizeH) + theScrollBar;
  63.     END
  64. ELSE
  65.     BEGIN
  66.     width := ICONMinWindowWidth;
  67.     iconsPerRow := minIconsPerRow;
  68.     END;
  69. GetWidth := width;
  70. END;
  71.  
  72. { *********************************************************************************** }
  73.  
  74. FUNCTION GetHeight: INTEGER;
  75.  
  76. VAR
  77.     height: INTEGER;
  78.  
  79. BEGIN
  80. height := PickStdHeight;
  81. IF height > ICONMinWindowHeight THEN
  82.     height := (height DIV listCellSizeV) * listCellSizeV
  83. ELSE
  84.     height := ICONMinWindowHeight;
  85. GetHeight := height;
  86. END;
  87.  
  88. { *********************************************************************************** }
  89.  
  90. PROCEDURE PickBirth(t: ResType; dad: ParentHandle);
  91.  
  92. VAR
  93.     pick: PickHandle;
  94.     iconsPerRow, width: INTEGER;
  95.  
  96. BEGIN
  97. pick := PickHandle(NewHandle(SIZEOF(PickRec)));
  98.  
  99. WITH pick^^ DO
  100.     BEGIN
  101.     father := dad;                                         { Back ptr to dad }
  102.     rType := t;                                             { Resource type }
  103.     viewBy := viewBySpecial;
  104.     ldefType := t;
  105.     cellSize.h := listCellSizeH;
  106.     cellSize.v := listCellSizeV;
  107.     END;
  108. width := GetWidth (iconsPerRow);        { Also sets iconsPerRow }
  109. IF NOT DoPickBirth(FALSE, TRUE, width, GetHeight, iconsPerRow, ResEdId, pick) THEN
  110.     DisposHandle (Handle(pick))
  111. ELSE
  112.     pick^^.rSize := ICONResourceSize;
  113. END;
  114.  
  115. { *********************************************************************************** }
  116.  
  117. { Everything except the grow box is taken care of for us by PickEvent.}
  118. PROCEDURE DoEvent(VAR evt: EventRecord; pick: PickHandle);
  119.  
  120. VAR
  121.     windPtr: WindowPtr;
  122.  
  123. BEGIN
  124. { Must do our own grow box manipulation so that the min size is set correctly. }
  125. IF (evt.what = mouseDown) & (FindWindow(evt.where, windPtr) = inGrow) THEN
  126.     GrowMyWindow (ICONMinWindowWidth, ICONMinWindowHeight, windPtr, pick^^.instances)
  127. ELSE
  128.     PickEvent(evt, pick);
  129. END;
  130.  
  131. { *********************************************************************************** }
  132.  
  133. { Everything is taken care of for us by PickInfoUp }
  134. PROCEDURE DoInfoUpdate(oldID, newID: INTEGER; pick: PickHandle);
  135.  
  136. BEGIN
  137. PickInfoUp(oldID, newID, pick);
  138. END;
  139.  
  140. { *********************************************************************************** }
  141.  
  142. FUNCTION IsThisYours (thing: Handle; pick: PickHandle): BOOLEAN;
  143.  
  144. BEGIN
  145. IsThisYours := FALSE;
  146. END;
  147.  
  148. { *********************************************************************************** }
  149.  
  150. PROCEDURE DoMenu(menu, item: INTEGER; pick: PickHandle);
  151.  
  152. BEGIN
  153. { Everything is taken care of for us by PickMenu. }
  154. PickMenu(TRUE, menu, item, pick);    { Do the normal picker stuff. }
  155. END;
  156.  
  157. END.
  158.